package com.nsl.my_youlai.mystar.easy_excel.check;

import com.nsl.my_youlai.mystar.easy_excel.model.ExcelReadCheck;
import com.nsl.my_youlai.mystar.easy_excel.model.ExcelStringRecorde;
import com.nsl.my_youlai.mystar.enums.NslEnumBaseI;
import com.nsl.my_youlai.mystar.enums.NslEnumTransformException;

import java.util.Map;

public class ExcelExceptionHandler {

    /**
     * @deprecated 已采用注解的形式，完成输入校验
     * @param propName
     * @param inputValue
     * @param exception
     * @param vo
     * @param prop2ExcelSheetHeadMap
     * @return
     * @param <E>
     */
    public static <E extends Enum<E> & NslEnumBaseI> ExcelReadCheck handleExcelException(String propName,Object inputValue, Exception exception, ExcelStringRecorde vo, Map<String,String> prop2ExcelSheetHeadMap){
        ExcelReadCheck readCheck=new ExcelReadCheck();
        readCheck.setRowIndex(vo.getRowIndex());
        readCheck.setHeadString(prop2ExcelSheetHeadMap.get(propName));
        readCheck.setExcelInputString(inputValue.toString());
        if(exception instanceof  NumberFormatException){
            readCheck.setTitle("输入类型不匹配");
            readCheck.setMessage("输入:"+readCheck.getExcelInputString()+" 不能转换成 "+"整数/小数");
            return readCheck;
        }
        if(exception instanceof NslEnumTransformException){
            readCheck.setTitle("非指定枚举值");
            readCheck.setMessage("输入:"+readCheck.getExcelInputString()+" 不在 "+NslEnumBaseI.getLabelRangeAsString(((NslEnumTransformException) exception).getTClass())+" 范围内");
            return readCheck;
        }



        throw new RuntimeException("抛出异常类型，未捕获到。");
    }
}
